﻿// IKmUnknown.h: interface for the IKmUnknown class.
//
//////////////////////////////////////////////////////////////////////

#if !defined(AFX_IKMUNKNOWN_H__6B053CD6_085E_4275_A163_3A130D8DCF91__INCLUDED_)
#define AFX_IKMUNKNOWN_H__6B053CD6_085E_4275_A163_3A130D8DCF91__INCLUDED_

#if _MSC_VER > 1000
#pragma once
#endif // _MSC_VER > 1000

class IKmUnknown
{
public:
	//virtual BOOL QueryInterface(IID iid, void** ppv) = 0;		// 询问接口
	virtual long AddRef(void) = 0;
	virtual long Release(void) = 0;
	virtual long GetRef(void) = 0;
};

template<class T>
class IKmUnknownImpl  : public T
{
public:
	IKmUnknownImpl()
	{
		m_lRef = 1;
	}
	virtual ~IKmUnknownImpl()
	{
	}

private:
	long	m_lRef;

public:
	virtual long AddRef(void) 
	{ 
		return InterlockedIncrement( &m_lRef ); 
	} 

	virtual long Release(void) 
	{ 
		if( InterlockedDecrement( &m_lRef ) == 0 ) 
		{
			delete this; 
			return 0;
		}
		return m_lRef; 
	} 

	virtual long GetRef(void)
	{
		return m_lRef;
	}
};

#endif // !defined(AFX_IKMUNKNOWN_H__6B053CD6_085E_4275_A163_3A130D8DCF91__INCLUDED_)
